package silo.dungeonbuddy;

import java.util.Vector;

public class Effect extends FlatImage
{
	private int row;
	private int column;
	
	public Effect(String eName, Start game,String ref, String IP, int eRow, int eCol, int eSizeX, int eSizeY)
	{
		super(eName,ref,game,eRow*(int)Math.floor(game.getHeight()/20),eCol*(int)Math.floor(game.getHeight()/20),eSizeX,eSizeY);
		Vector v = (Vector)game.getBoard().getSquareList().get(eRow);
		Square s = (Square)v.get(eCol);
		x=s.getX();
		y=s.getY();
		row = eRow;
		column = eCol;
	}//constructors
	
	//TODO: ensure that the squares' occupees vector manipulation will work with the move subs below:
	
	public void moveTo(Square s)
	{
		Vector v = (Vector)game.getBoard().getSquareList().get(row);
		Square sq = (Square)v.get(column);
		sq.getOccupees().remove(this);
		row=s.getRow();
		column=s.getColumn();
		v = (Vector)game.getBoard().getSquareList().get(row);
		sq = (Square)v.get(column);
		x=sq.getX();
		y=sq.getY();
		sq.getOccupees().add(this);
	}//moveTo
	
	public void moveUp()
	{
		if(row>0)
		{
			Vector v = (Vector)game.getBoard().getSquareList().get(row);
			Square sq = (Square)v.get(column);
			sq.getOccupees().remove(this);
			row=row-1;
			//square=game.getBoard().getSquareList()[row][column];
			v = (Vector)game.getBoard().getSquareList().get(row);
			sq = (Square)v.get(column);
			x=sq.getX();
			y=sq.getY();
			sq.getOccupees().add(this);
		}
	}
	public void moveDown()
	{
		if(row<game.getBoard().getHeight())
		{
			Vector v = (Vector)game.getBoard().getSquareList().get(row);
			Square sq = (Square)v.get(column);
			sq.getOccupees().remove(this);
			row=row+1;
			//square=game.getBoard().getSquareList()[row][column];
			v = (Vector)game.getBoard().getSquareList().get(row);
			sq = (Square)v.get(column);
			x=sq.getX();
			y=sq.getY();
			sq.getOccupees().add(this);
		}
	}
	public void moveLeft()
	{
		if(column>0)
		{
			Vector v = (Vector)game.getBoard().getSquareList().get(row);
			Square sq = (Square)v.get(column);
			sq.getOccupees().remove(this);
			column=column-1;
			//square=game.getBoard().getSquareList()[row][column];
			v = (Vector)game.getBoard().getSquareList().get(row);
			sq = (Square)v.get(column);
			x=sq.getX();
			y=sq.getY();
			sq.getOccupees().add(this);
		}
	}
	public void moveRight()
	{
		if(column<game.getBoard().getHeight())
		{
			Vector v = (Vector)game.getBoard().getSquareList().get(row);
			Square sq = (Square)v.get(column);
			sq.getOccupees().remove(this);
			column=column+1;
			//square=game.getBoard().getSquareList()[row][column];
			v = (Vector)game.getBoard().getSquareList().get(row);
			sq = (Square)v.get(column);
			x=sq.getX();
			y=sq.getY();
			sq.getOccupees().add(this);
		}
	}
	public void moveUpLeft()
	{
		if((row>0)&&(column>0))
		{
			Vector v = (Vector)game.getBoard().getSquareList().get(row);
			Square sq = (Square)v.get(column);
			sq.getOccupees().remove(this);
			column=column-1;
			row=row-1;
			//square=game.getBoard().getSquareList()[row][column];
			v = (Vector)game.getBoard().getSquareList().get(row);
			sq = (Square)v.get(column);
			x=sq.getX();
			y=sq.getY();
			sq.getOccupees().add(this);
		}
	}
	public void moveDownLeft()
	{
		if((row<game.getBoard().getHeight())&&(column>0))
		{
			Vector v = (Vector)game.getBoard().getSquareList().get(row);
			Square sq = (Square)v.get(column);
			sq.getOccupees().remove(this);
			column=column-1;
			row=row+1;
			//square=game.getBoard().getSquareList()[row][column];
			v = (Vector)game.getBoard().getSquareList().get(row);
			sq = (Square)v.get(column);
			x=sq.getX();
			y=sq.getY();
			sq.getOccupees().add(this);
		}
	}
	public void moveUpRight()
	{
		if((row>0)&&(column<game.getBoard().getWidth()))
		{
			Vector v = (Vector)game.getBoard().getSquareList().get(row);
			Square sq = (Square)v.get(column);
			sq.getOccupees().remove(this);
			column=column+1;
			row=row-1;
			//square=game.getBoard().getSquareList()[row][column];
			v = (Vector)game.getBoard().getSquareList().get(row);
			sq = (Square)v.get(column);
			x=sq.getX();
			y=sq.getY();
			sq.getOccupees().add(this);
		}
	}
	public void moveDownRight()
	{
		if((row<game.getBoard().getHeight())&&(column<game.getBoard().getWidth()))
		{
			Vector v = (Vector)game.getBoard().getSquareList().get(row);
			Square sq = (Square)v.get(column);
			sq.getOccupees().remove(this);
			column=column+1;
			row=row+1;
			//square=game.getBoard().getSquareList()[row][column];
			v = (Vector)game.getBoard().getSquareList().get(row);
			sq = (Square)v.get(column);
			x=sq.getX();
			y=sq.getY();
			sq.getOccupees().add(this);
		}
	}
	
	//GETTERS
	public int getRow()
	{
		return row;
	}
	public int getColumn()
	{
		return column;
	}
	
	//SETTERS
	
	//toString
	public String toString()
	{
		if(visible)
		{
			return "5" + "," + x + "," + y + "," + spriteRef + "," + sizeX + "," + sizeY + "," + "1" + "," + row + "," + column + ",";
		}else
		{
			return "5" + "," + x + "," + y + "," + spriteRef + "," + sizeX + "," + sizeY + "," + "0" + "," + row + "," + column + ",";
		}
	}//toString
}//class Effect